//
//  aes_service.cpp
// ~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2013-2014 Razvan Coca (razvan dot coca at  gmail dot com)
// 
//


#include <boost/thread.hpp>
#include "aes_service.hpp"
namespace  components
{
namespace encrypt
{
boost::mutex aes_service::create_mutex_;
int aes_service::strand_index=0;
std::vector<strand_pointer_t> aes_service::strands_;
byte  aes_service::hw_threads=boost::thread::hardware_concurrency();
const int aes_service::DEFAULT_KEYSIZE     =   CryptoPP::AES::DEFAULT_KEYLENGTH;
const int aes_service::DEFAULT_BLOCKSIZE   =   CryptoPP::AES::BLOCKSIZE;

strand_pointer_t aes_service::get_strand(boost::asio::io_service& ios)
{
    boost::mutex::scoped_lock Lock(create_mutex_);
    if(strands_.size()<hw_threads)
        strands_.push_back( boost::make_shared<strand_t>(ios) );
    strand_pointer_t s=strands_[strand_index];
    strand_index=(strand_index+1)%hw_threads;
    return s;
}
}
}
